/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Player;

import Game.NewGame;
import IO.models.ItemsConfig;
import IO.models.PlayerConfig;
import Inrterface.Messages;
import Items.Item;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author insane
 */
public class Inventory {

    private static Inventory instance;
    private int[] belt = {1,1,1,0,0,0,0,0,0,0};

    public static Inventory getInstance() {
        if (instance == null) {
            instance = new Inventory();
        }
        return instance;
    }

    private Inventory() {
    }

    public void addItems(Item item) throws ClassNotFoundException, FileNotFoundException, IOException {
        ArrayList InventoryItems = NewGame.getPlayer().getInventoryItems();
        if (InventoryItems == null) {
            InventoryItems = new ArrayList();
            for (int a = 0; a < 20; a++) {
                InventoryItems.add(null);
            }
        }
        for (int a = 0; a < 20; a++) {
            if (InventoryItems.get(a) == null) {
                InventoryItems.add(item);
                NewGame.getPlayer().setInventoryItems(InventoryItems);
                PlayerConfig.getInstance().save();
                return;
            }
        }
        Messages.getInstance().add("inventory is full");
    }

    public void delItems() {
    }

    public void drawInventory() {
    }

    public void addPotion(int p) {
        for (int i = 0; i < getBelt().length; i++) {
            if (getBelt()[i] == 0) {
                getBelt()[i] = p;
                return;
            }
        }
    }

    /**
     * @return the belt
     */
    public int[] getBelt() {
        return belt;
    }

    /**
     * @param belt the belt to set
     */
    public void setBelt(int[] belt) {
        this.belt = belt;
    }

    public void drinkPotion(int i) {
        if(this.belt[i]==0) return;
        if(this.belt[i]==1) NewGame.getPlayer().addLive(NewGame.getPlayer().getMaxHealth() / 3);
        this.belt[i]=0;
    }
}
